package com.run_java_test.test2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

public class BeanRegistrar {
    public static void registerBean(ApplicationContext context, Class<?> clazz, String beanName) {
        if (context instanceof GenericApplicationContext) {
            GenericApplicationContext appContext = (GenericApplicationContext) context;
            appContext.registerBean(beanName, clazz); // 注册 Bean 并指定名称
            appContext.refresh(); // 刷新容器，确保新类能被 Spring 托管
        }
    }

}
